var pomelo = require('pomelo');
var dispatcher = require('../../util/dispatcher');
var rooms = require('../../model/rooms');
var exports = module.exports;

exports.sendEvent = function(msg,uid,event)
{
    var sid = exports.getFrontendSid(uid);
    //向敌方发送消息
    var target = [{'uid':uid,'sid':sid}];
    pomelo.app.channelService.pushMessageByUids(event,msg,target);
    console.info('send event %s to %d',event,uid);
}

exports.getFrontendSid = function(uid)
{
    var servers = pomelo.app.getServersByType('connector');
    return dispatcher.dispatch(uid,servers).id;
}

exports.findEnemyByTable = function(player,table)
{
    var uid1 = table.uid1;
    var uid2 = table.uid2;
    if(table)
    {
        return (player.uid == uid1.uid)?uid2:uid1;
    }
    return 0;
}